package cn.le.netty.serious;

import com.alibaba.fastjson.JSONObject;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageDecoder;

import java.util.List;

public class JSONDecoder extends MessageToMessageDecoder<ByteBuf> {
    protected void decode(ChannelHandlerContext channelHandlerContext, ByteBuf msg, List list) throws Exception {
        int len = msg.readableBytes();//可以用的数据长度
        byte[] data = new byte[len];
        msg.getBytes(msg.readerIndex(),data,0,len);
        list.add(JSONObject.parseObject(new String(data)));
    }
}
